# 循环输入10个人的信息（姓名，年龄，性别，身高），并存储到数据库中
import pymysql


class PyMySQL:
    def __init__(self, host, user, password, database, port=3306, charset='utf8'):
        self.host = host
        self.user = user
        self.password = password
        self.database = database
        self.port = port
        self.charset = charset

    def insert(self, data=None):
        db = pymysql.connect(
            host=self.host,
            user=self.user,
            password=self.password,
            database=self.database,
            port=self.port,
            charset=self.charset
        )
        try:
            with db.cursor() as cursor:
                cursor.execute(f"insert into person values {data}")
              # cursor.execute("insert into person values (%s,%s,%s,%s)", data)
                db.commit()
                print("插入成功")
        except Exception as e:
            print("插入失败", e)
        finally:
            db.close()


n = 0
while n < 1:
    add = PyMySQL('localhost', 'root', '122311', 'test')
    data = (input("请输入姓名："), int(input("请输入年龄：")), input("请输入性别："), float(input("请输入身高：")))
    add.insert(data)
    n += 1
